/*
 * Copyright (c) 2025 Li Auto Inc. and its affiliates
 * Licensed under the Apache License, Version 2.0(the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/*
 * Description: Os Application Configuration
 * AutoGenerate Code, DO NOT EDIT!!!
 * {{get_generation_time()}}
 * {{get_project_name()}}
 * {{get_vcos_version()}}
 */

 /* Including File */
#include <nuttx/config.h>
#include "application_cfg.h"
#include "os_compiler_cfg.h"
#include "task_cfg.h"
#include "isr_cfg.h"
#include "counter_cfg.h"
#include "os_core.h"
#include "core_cfg.h"
#if defined(CONFIG_RT_FRAMEWORK_SCHTBL) && (CONFIG_RT_FRAMEWORK_SCHTBL == 1)
#include "schedtable_cfg.h"
#endif /* (CONFIG_RT_FRAMEWORK_SCHTBL == 1) */

/* Local Macro Definition */

/* Local Enumeration Definition */

{%- set app_cfg = get_app_cfg() %}
{%- for app_key, app_val in app_cfg.items() %}
    {% set bsw_appname = app_val["BswAppName"] %}
DeclareOsApplication({{app_cfg[bsw_appname]["AppInstSection"]}}, {{app_key}}) = {
    /* .instance  = */           &OSAPPOBJVAR({{app_key}}),
    /* .app_name = */            "{{app_key}}",
    {%- if app_val["AppTaskList"]: %}
    /* .task_refs  = */          {{app_val["AppTaskTable"]}},
    /* .task_count  = */         &{{app_val["AppTaskTable"]}}_size,
    {%- else: %}
    /* .task_refs  = */          NULL_PTR,
    /* .task_count  = */         NULL_PTR,
    {%- endif %}
    {%- if app_val["AppIsrList"]: %}
    /* .isr_refs  = */       {{app_val["AppIsrTable"]}},
    /* .isr_count  = */      &{{app_val["AppIsrTable"]}}_size,
    {%- else: %}
    /* .isr_refs  = */       NULL_PTR,
    /* .isr_count  = */      NULL_PTR,
    {%- endif %}
#if defined(CONFIG_RT_FRAMEWORK_SCHTBL) && (CONFIG_RT_FRAMEWORK_SCHTBL == 1)
    {%- if app_val["AppScheduleTableList"] and app_val["AppScheduleTableList"]|length > 0 %}
    /* .scht_refs  = */          {{app_val["AppSchedTblTable"]}},
    /* .scht_count  = */         &{{app_val["AppSchedTblTable"]}}_size,
    {%- else %}
    /* .scht_refs  = */          NULL_PTR,
    /* .scht_count  = */         NULL_PTR,
    {%- endif %}
#endif /* (CONFIG_RT_FRAMEWORK_SCHTBL == 1) */
#if defined(CONFIG_RT_FRAMEWORK_COUNTER) && (CONFIG_RT_FRAMEWORK_COUNTER == 1)
    {%- if app_val["AppCounterList"] and app_val["AppCounterList"]|length > 0 %}
    /* .counter_refs  = */       {{app_val["AppCounterTable"]}},
    /* .counter_count  = */      &{{app_val["AppCounterTable"]}}_size,
    {%- else %}
    /* .counter_refs  = */       NULL_PTR,
    /* .counter_count  = */      NULL_PTR,
    {%- endif %}
#endif
    /* .core_id  = */            OS_CORE_ID_{{app_val["CoreNumber"]}},
    /* .AppId  = */             {{app_val["AppId"]}},
    /* .IsPrivileged  = */      {{app_val["AppPrivileged"]}},
};

{%- endfor %}

{%- set core_info = get_core_configs() %}

#define OS_START_SEC_CONST
#include "os_memmap.h"
{% for k, v in core_info.items(): %}
{%- set core_num = k.lstrip("Os_Core") %}
/* {{k}} config referenc table */
CONSTP2CONST(os_app_cfg_t, AUTOMATIC, OS_CONST) os_core{{core_num}}_apps_cfg_ref_table[] = {
{%- for app_key, app_val in app_cfg.items() %}
    {%- if app_val["CoreNumber"] == core_num: %}
    &OSAPPCFGVAR({{app_key}}),
    {%- endif %}
{%- endfor %}
};
CONST(OsObjIndexType, OS_CONST) os_core{{core_num}}_apps_cfg_ref_table_size = (OsObjIndexType)NELEMENTS(os_core{{core_num}}_apps_cfg_ref_table);
{% endfor %}
#define OS_STOP_SEC_CONST
#include "os_memmap.h"

DeclareOsRefTable(app, OS_APPLICATION_CNT) = {
{%- for app, appval in app_cfg.items() %}
    &OSAPPCFGVAR({{app}}),
{%- endfor %}
};

